package com.wzy.service.schedule.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.wzy.common.base.redis.RedisUtil;
import com.wzy.common.base.result.R;
import com.wzy.service.schedule.entity.Schedule;
import com.wzy.service.schedule.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wuzhengyu
 * @since 2021-03-31
 */
@RestController
@RequestMapping("/schedule")
public class ScheduleController {

    @Autowired
    ScheduleService scheduleService;
    @Autowired
    RedisUtil redisUtil;


    @RequestMapping(value = "/schedule", method = RequestMethod.GET)
    public R getSchedule(@RequestParam String uid) {
        Schedule schedule = scheduleService.getSchedule(uid);
        return R.ok().data("schedule", schedule);
    }

    @PutMapping("/schedule")
    public R updateSchedule(@RequestBody Schedule schedule) {
        schedule.setGmtModified(new Date());
        scheduleService.update(schedule, Wrappers.<Schedule>lambdaUpdate().eq(Schedule::getUid, schedule.getUid()));

        return R.ok();
    }

    @PostMapping("/schedule")
    public R insertSchedule(String uid) {
        Schedule schedule = new Schedule();
        schedule.setGmtModified(new Date());
        schedule.setGmtCreate(new Date());
        schedule.setUid(Long.valueOf(uid));
        schedule.setName(uid);
        Date date1 = new Date();
        date1.setHours(0);
        date1.setMinutes(5);
        schedule.setD1(date1);
        Date date2 = new Date();
        date2.setHours(0);
        date2.setMinutes(30);
        schedule.setD2(date2);
        Date date3 = new Date();
        date3.setHours(12);
        date3.setMinutes(0);
        schedule.setD3(date3);
        schedule.setC1(1);
        schedule.setC2(2);
        schedule.setC3(4);
        schedule.setC4(7);
        scheduleService.save(schedule);
        return R.ok();
    }



}

